package com.fzkj.functional;

import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @ description
 * @ author yaya
 * @ since 2024/8/6
 */
public class Application {

    private static final Map<String, User> userMap = Map.of(
            "zhangsan", new User("zhangsan", 18)
    , "lisi", new User("lisi", 19));


    public static void main(String[] args) {

//        Function<String, String> function = (String s) -> {
//            return s + "!!!";
//        };

//        System.out.println(function.apply("hello world"));

        test(userMap::get, () -> new User("lisi", 19), user -> {
            if (user.name.equals("lisi")) {
                System.out.println("hahah");
            }
        });

    }


    private static void test(Function<String, User> userFunc, Supplier<User> userSupplier, Consumer<User> userConsumer) {
        User user = userFunc.apply("zhangsan1");
        if (user == null) {
            user = userSupplier.get();
        }
        userConsumer.accept(user);
        System.out.println(user);
    }


    static class User{
        private String name;
        private Integer age;

        public User(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
